Ottawa

row

Buildings

182,225

Users

177

Average number of tags

4.4

row

Buildings mapped

row

Buildings by type

Missing address fields in percentage

Number of tags

Gatineau

row

Buildings

81,446

Users

92

Average number of tags

6.14

row

Buildings mapped

row

Buildings by type

Missing address fields in percentage

Number of tags

Ottawa-Gatineau

row

Buildings

263,670

Users

233

Average number of tags

4.94

row

Buildings mapped

row

Buildings by type

Missing address fields in percentage

Number of tags

Data

August 2016

March 2017

---
title: "Crowdsourcing: `r format(Sys.Date(), format='%B %Y')`"
output: 
  flexdashboard::flex_dashboard:
    theme: lumen
    orientation: rows
    source_code: embed
---

```{r global, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(ggthemes)
library(lubridate)
library(leaflet)
library(rgdal)
library(forcats)
library(scales)
library(DT)
library(plotly)
library(stringr)
library(rgeos)
library(maptools)

date <- Sys.Date()
date2 <- as.character(date)
date3 <- str_replace_all(date, "-", "")

datePath <- file.path("../OSMdata", Sys.Date())

if(!file.exists(datePath)) dir.create(datePath)

ontario <- "http://download.geofabrik.de/north-america/canada/ontario-latest.osm.pbf"
quebec <- "http://download.geofabrik.de/north-america/canada/quebec-latest.osm.pbf"

FileNameOnt <- "ontario-latest.osm.pbf"
FileNameOnt <- str_replace_all(FileNameOnt, "latest", date3)
FileNameQueb <- "quebec-latest.osm.pbf"
FileNameQueb <- str_replace_all(FileNameQueb, "latest", date3)


OntFile <- file.path(datePath, FileNameOnt)
QuebFile <- file.path(datePath, FileNameQueb)

download.file(ontario, destfile = OntFile)
download.file(quebec, destfile = QuebFile)

system(paste("cp ~/Projects/OSMdata/Geometries/*.poly", datePath))

# The first part requires system commands line. This was done on a mac. On a PC, system() 
#must be replaced by shell().

# 1. Ottawa
#Here, " needs to be escaped to work (with a \)    
system(paste("cd", datePath, "&& osmosis \\
       --rbf", FileNameOnt, "\\
       --bounding-polygon file=\"Ottawa.poly\" \\
       completeWays=yes \\
       --wx ottawa.osm"))

#Same thing, a \ needs to be escaped with another \
system(paste("cd", datePath, "&& osmosis \\
       --rx ottawa.osm \\
       --tf accept-ways 'building=*' \\
       --tf reject-relations \\
       --used-node \\
       --wx OttBuildW.osm"))


system(paste("cd", datePath, 
       "&& node --max_old_space_size=8192 `which osmtogeojson` OttBuildW.osm > OttBuildW.geojson"))

# 2. Gatineau
#Here, " needs to be escaped to work (with a \)    
system(paste("cd", datePath, "&& osmosis \\
       --rbf", FileNameQueb, "\\
       --bounding-polygon file=\"Gatineau.poly\" \\
       completeWays=yes \\
       --wx gatineau.osm"))

system(paste("cd", datePath, "&& osmosis \\
       --rx gatineau.osm \\
       --tf accept-ways 'building=*' \\
       --tf reject-relations \\
       --used-node \\
       --wx GatBuildW.osm"))

system(paste("cd", datePath, 
       "&& node --max_old_space_size=8192 `which osmtogeojson` GatBuildW.osm > GatBuildW.geojson"))

# 3. Ottawa and Gatineau
system(paste("cd", datePath, "&& osmosis --rx ottawa.osm --rx gatineau.osm --merge --wx OttGat.osm"))

system(paste("cd", datePath, "&& osmosis \\
      --rx OttGat.osm \\
      --tf accept-ways 'building=*' \\
       --tf reject-relations \\
       --used-node \\
       --wx OttGatBuildW.osm"))
       
system(paste("cd", datePath, 
       "&& node --max_old_space_size=8192 `which osmtogeojson` OttGatBuildW.osm > OttGatBuildW.geojson"))


OttJSON <- file.path(datePath, "OttBuildW.geojson")
GatJSON <- file.path(datePath, "GatBuildW.geojson")
OttGatJSON <- file.path(datePath, "OttGatBuildW.geojson")

BuildOtt <- readOGR(OttJSON, "OGRGeoJSON", require_geomType="wkbPolygon")
BuildGat <- readOGR(GatJSON, "OGRGeoJSON", require_geomType="wkbPolygon")
BuildOttGat <- readOGR(OttGatJSON, "OGRGeoJSON", require_geomType="wkbPolygon")

OttData <-BuildOtt@data
GatData <- BuildGat@data
OttGatData <- BuildOttGat@data

OttData$timestamp <- as_date(ymd_hms(OttData$timestamp))
GatData$timestamp <- as_date(ymd_hms(GatData$timestamp))
OttGatData$timestamp <- as_date(ymd_hms(OttGatData$timestamp))

# 1. Get number of buildings
OttNumBuild <- tally(OttData) %>% 
  mutate(buildings = n) %>% 
  select(-n) %>% 
  unlist(use.names = FALSE)

GatNumBuild <- tally(GatData) %>% 
  mutate(buildings = n) %>% 
  select(-n) %>% 
  unlist(use.names = FALSE)

OttGatNumBuild <- tally(OttGatData) %>% 
  mutate(buildings = n) %>% 
  select(-n) %>% 
  unlist(use.names = FALSE)

# 2. Get Month
month <- Sys.Date()

# 3. Get num of users
OttUsersBuild <- OttData %>% 
  summarise(users = n_distinct(user)) %>% 
  unlist(use.names = FALSE)

GatUsersBuild <- GatData %>% 
  summarise(users = n_distinct(user)) %>% 
  unlist(use.names = FALSE)

OttGatUsersBuild <- OttGatData %>% 
  summarise(users = n_distinct(user)) %>% 
  unlist(use.names = FALSE)

# 4. calculate number of tags by removing common attributes, sum only non-NAs, sum the rows.

#remove columns with no values before counting tags
OttData2 <-  OttData %>% 
  select_if(colSums(!is.na(.)) > 0)

GatData2 <-  GatData %>% 
  select_if(colSums(!is.na(.)) > 0)

OttGatData2 <-  OttGatData %>% 
  select_if(colSums(!is.na(.)) > 0)

rownames(OttData2) <- c()
rownames(GatData2) <- c()
rownames(OttGatData2) <- c()

#Remove common attributes before counting tags
CommAttr <- c("id", "user", "uid", "timestamp", "version", "changeset")


OttTagBuild <- OttData2 %>%
  select(-one_of(CommAttr)) %>% 
  summarise_each(funs(sum(!is.na(.)))) %>% 
  mutate(tagsBuild = rowSums(.)) %>% 
  select(tagsBuild) %>% 
  unlist(use.names = FALSE)

GatTagBuild <- GatData2 %>%
  select(-one_of(CommAttr)) %>% 
  summarise_each(funs(sum(!is.na(.)))) %>% 
  mutate(tagsBuild = rowSums(.)) %>% 
  select(tagsBuild) %>% 
  unlist(use.names = FALSE)

OttGatTagBuild <- OttGatData2 %>%
  select(-one_of(CommAttr)) %>% 
  summarise_each(funs(sum(!is.na(.)))) %>% 
  mutate(tagsBuild = rowSums(.)) %>% 
  select(tagsBuild) %>% 
  unlist(use.names = FALSE)

# 5. average tags per building
OttAvgTagBuild <- OttTagBuild / OttNumBuild
GatAvgTagBuild <- GatTagBuild / GatNumBuild
OttGatAvgTagBuild <- OttGatTagBuild / OttGatNumBuild

# Make data frame 
cities <- c("Ottawa", "Gatineau", "Ott/Gat")
month <- c(date, date, date)
buildings <- c(OttNumBuild, GatNumBuild, OttGatNumBuild)
usersBuild <- c(OttUsersBuild, GatUsersBuild, OttGatUsersBuild)
tagsBuild <- c(OttTagBuild, GatTagBuild, OttGatTagBuild)
averTagsBuild <- c(OttAvgTagBuild, GatAvgTagBuild, OttGatAvgTagBuild) 


Build <- data.frame(cities, month, buildings, usersBuild, tagsBuild, averTagsBuild)

data <- read.csv('~/Projects/AutoJarcid/Buildings.csv', header = TRUE)
data$month <- ymd(data$month)

Build <- full_join(Build, data)
Build <- arrange(Build, month)

write.csv(Build, '~/Projects/AutoJarcid/Buildings.csv', row.names = F)

MapName <- "timeStamp.jpg"
MapDate <- str_replace_all(MapName, "timeStamp", date2)

theme1 <- theme(panel.grid.major = element_blank(), 
                panel.grid.minor = element_blank(),
                axis.title.x = element_blank(), 
                axis.title.y = element_blank(),
                axis.text.x = element_blank(), 
                axis.text.y = element_blank(),
                axis.ticks = element_blank(),
                panel.background = element_rect(fill = "#333333"))

system.time({
  jpeg(MapDate, width=1920, height=1166)
  gg <- ggplot(data = BuildOttGat, aes(x = long, y = lat, group = group)) + 
    geom_polygon(fill=NA, color="white") + 
    theme1 +
    annotate("text", label = date, x = -76.2, y = 45.05, 
             size = 14, colour = "white")
  print(gg)
  dev.off()
})

data <- read.csv('~/Projects/AutoJarcid/Buildings.csv', header = TRUE)
data2 <- data
data3 <- data
data$averTagsBuild <- round(data$averTagsBuild, 2)
data$month <- month(data$month, label = TRUE)
data2$month <- ymd(data2$month)

```


Ottawa {data-navmenu="Cities"}
=======================================================================
row
-----------------------------------------------------------------------

###Buildings {.value-box}
```{r, echo=FALSE}
buildOtt <- data2 %>%
  filter(cities == "Ottawa") %>%
  top_n(1, month) %>%
  select(buildings)

valueBox(comma(buildOtt), icon = "ion-ios-home-outline", color = "#9ecae1")
```

###Users {.value-box}
```{r}
usersOtt <- data2 %>%
  filter(cities == "Ottawa") %>%
  top_n(1, month) %>%
  select(usersBuild)

valueBox(usersOtt, icon = "ion-ios-people-outline", color = "#9ecae1")
```

###Average number of tags {.value-box}
```{r}
tagsOtt <- data2 %>%
  filter(cities == "Ottawa") %>%
  top_n(1, month) %>%
  select(averTagsBuild)

tagsOtt$averTagsBuild <- round(tagsOtt$averTagsBuild, 2)

valueBox(tagsOtt, icon = "ion-ios-pricetags-outline", color = "#9ecae1")
```


row {data-height=400}
-----------------------------------------------------------------------

###Buildings mapped

```{r, echo=FALSE, message=FALSE}
 OttBuild <- data2 %>%
   filter(cities=="Ottawa") %>%
   select(cities, month, buildings)

#With a geom_line plot, you need to add group = 1 if only one group of observations
#to avoid the warning message each is obs is one group
gg <- ggplot(OttBuild, aes(month, buildings, group = 1, text = comma(buildings)))
gg <- gg + geom_line(position = "identity", color="#6baed6")
gg <- gg + scale_y_continuous(labels = comma)
gg <- gg + scale_x_date(breaks = as.Date(seq(as.Date("2016-07-15"), 
                            as.Date(date), by = "1 month")), date_labels ="%b %y")
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major.x= element_blank())
gg <- gg + theme(panel.grid.major.y=element_line(linetype = "dashed"))
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks=element_line(colour="#ececec"))
gg <- gg + theme(axis.text.x=element_text(size=12))
gg <- gg + theme(axis.text.y=element_text(size=10))
ggplotly(gg, tooltip = "text")
```

row {data-height=600}
-------------------------------------------------------------------
###Buildings by type 
```{r}
buildType <- BuildOtt@data %>% 
  group_by(building) %>%
  summarise(numB = length(building)) %>%
  arrange(desc(numB)) %>%
  filter(numB > 50)

gg <- ggplot(buildType, aes(x=numB, y=reorder(building, numB), text = comma(numB)))
gg <- gg + geom_segment(aes(xend = 0, yend=building), color="#ececec")
gg <- gg + geom_point(color = "#3282bd", size = 2)
gg <- gg + scale_x_continuous(expand = c(0.1,0), labels = comma)
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major = element_blank())
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks.y=element_blank())
gg <- gg + theme(axis.text.x=element_text(size=9))
gg <- gg + theme(axis.text.y=element_text(size=12))
ggplotly(gg, tooltip = "text")
```

### Missing address fields in percentage
```{r}

MissAddOtt <- BuildOtt@data %>%
  select(addr.street, addr.housenumber, addr.city, addr.postcode)


MeanAddrOtt <- MissAddOtt %>%
  summarise_all(funs(mean(is.na(.))*100)) %>%
  gather(Field, meanNA) %>%
  mutate(Field = fct_recode(Field, "Street" = "addr.street", 
                            "Street Number" = "addr.housenumber",
                            "City" = "addr.city",
                            "Postal Code" = "addr.postcode"))

gg <- ggplot(MeanAddrOtt, aes(x=reorder(Field, meanNA), y=meanNA, text = round(meanNA, 2)))
gg <- gg + geom_segment(aes(xend = Field, yend=0), color="#ececec")
gg <- gg + geom_point(color = "#3282bd", size = 2)
gg <- gg + coord_flip()
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major = element_blank())
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks.y=element_blank())
gg <- gg + theme(axis.text.x=element_text(size=10))
gg <- gg + theme(axis.text.y=element_text(size=12))
ggplotly(gg, tooltip = "text")
```


###Number of tags
```{r}

OttTagsBuild <- data3 %>%
  filter(cities=="Ottawa") %>%
  select(cities, month, tagsBuild) %>%
  mutate(month = fct_recode(month, "2016-08-30" = "2016-08-01")) %>%
  mutate(month = ymd(month))

gg <- ggplot(OttTagsBuild, aes(x=tagsBuild, y=month, text = comma(tagsBuild)))
gg <- gg + geom_segment(aes(xend = 0, yend=month), color="#ececec")
gg <- gg + geom_point(color = "#3282bd", size = 2)
gg <- gg + scale_x_continuous(expand = c(0.1,0), labels = comma)
gg <- gg + scale_y_date(breaks = as.Date(seq(as.Date("2016-08-25"), 
                            as.Date(date), by = "1 month")), date_labels ="%b %y")
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major = element_blank())
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks.y=element_blank())
gg <- gg + theme(axis.text.x=element_text(size=10))
gg <- gg + theme(axis.text.y=element_text(size=12))
ggplotly(gg, tooltip = "text")
```

Gatineau {data-navmenu="Cities"}
=======================================================================
row
-----------------------------------------------------------------------

###Buildings {.value-box}
```{r, echo=FALSE}
buildGat <- data2 %>%
  filter(cities == "Gatineau") %>%
  top_n(1, month) %>%
  select(buildings)

valueBox(comma(buildGat), icon = "ion-ios-home-outline", color = "#9ecae1")
```

###Users {.value-box}
```{r}
usersGat <- data2 %>%
  filter(cities == "Gatineau") %>%
  top_n(1, month) %>%
  select(usersBuild)

valueBox(usersGat, icon = "ion-ios-people-outline", color = "#9ecae1")
```

###Average number of tags {.value-box}
```{r}
tagsGat <- data2 %>%
  filter(cities == "Gatineau") %>%
  top_n(1, month) %>%
  select(averTagsBuild)

tagsGat$averTagsBuild <- round(tagsGat$averTagsBuild, 2)

valueBox(tagsGat, icon = "ion-ios-pricetags-outline", color = "#9ecae1")
```


row {data-height=400}
-----------------------------------------------------------------------

###Buildings mapped
```{r, echo=FALSE, message=FALSE}
 GatBuild <- data2 %>%
   filter(cities=="Gatineau") %>%
   select(cities, month, buildings)

#With a geom_line plot, you need to add group = 1 if only one group of observations
#to avoid the warning message each is obs is one group
gg <- ggplot(GatBuild, aes(month, buildings, group = 1, text = comma(buildings)))
gg <- gg + geom_line(position = "identity", color="#6baed6")
gg <- gg + scale_y_continuous(labels = comma)
gg <- gg + scale_x_date(breaks = as.Date(seq(as.Date("2016-07-15"), 
                            as.Date(date), by = "1 month")), date_labels ="%b %y")
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major.x= element_blank())
gg <- gg + theme(panel.grid.major.y=element_line(linetype = "dashed"))
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks=element_line(colour="#ececec"))
gg <- gg + theme(axis.text.x=element_text(size=12))
gg <- gg + theme(axis.text.y=element_text(size=10))
ggplotly(gg, tooltip = "text")
```

row {data-height=600}
-------------------------------------------------------------------
###Buildings by type
```{r}
buildTypeGat <- BuildGat@data %>% 
  group_by(building) %>%
  summarise(numB = length(building)) %>%
  arrange(desc(numB)) %>%
  filter(numB > 50)

gg <- ggplot(buildTypeGat, aes(x=numB, y=reorder(building, numB), text = comma(numB)))
gg <- gg + geom_segment(aes(xend = 0, yend=building), color="#ececec")
gg <- gg + geom_point(color = "#3282bd", size = 2)
gg <- gg + scale_x_continuous(expand = c(0.1,0), labels = comma)
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major = element_blank())
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks.y=element_blank())
gg <- gg + theme(axis.text.x=element_text(size=9))
gg <- gg + theme(axis.text.y=element_text(size=12))
ggplotly(gg, tooltip = "text")
```

### Missing address fields in percentage
```{r}

MissAddGat <- BuildGat@data %>%
  select(addr.street, addr.housenumber, addr.city, addr.postcode)


MeanAddrGat <- MissAddGat %>%
  summarise_all(funs(mean(is.na(.))*100)) %>%
  gather(Field, meanNA) %>%
  mutate(Field = fct_recode(Field, "Street" = "addr.street", 
                            "Street Number" = "addr.housenumber",
                            "City" = "addr.city",
                            "Postal Code" = "addr.postcode"))

gg <- ggplot(MeanAddrGat, aes(x=reorder(Field, meanNA), y=meanNA, text = round(meanNA, 2)))
gg <- gg + geom_segment(aes(xend = Field, yend=0), color="#ececec")
gg <- gg + geom_point(color = "#3282bd", size = 2)
gg <- gg + coord_flip()
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major = element_blank())
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks.y=element_blank())
gg <- gg + theme(axis.text.x=element_text(size=10))
gg <- gg + theme(axis.text.y=element_text(size=12))
ggplotly(gg, tooltip = "text")
```

###Number of tags

```{r}

GatTagsBuild <- data3 %>%
  filter(cities=="Gatineau") %>%
  select(cities, month, tagsBuild) %>%
  mutate(month = fct_recode(month, "2016-08-30" = "2016-08-01")) %>%
  mutate(month = ymd(month))

#28 because of February
gg <- ggplot(GatTagsBuild, aes(x=tagsBuild, y=month, text = comma(tagsBuild)))
gg <- gg + geom_segment(aes(xend = 0, yend=month), color="#ececec")
gg <- gg + geom_point(color = "#3282bd", size = 2)
gg <- gg + scale_x_continuous(expand = c(0.1,0), labels = comma)
gg <- gg + scale_y_date(breaks = as.Date(seq(as.Date("2016-08-25"), 
                            as.Date(date), by = "1 month")), date_labels ="%b %y")
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major = element_blank())
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks.y=element_blank())
gg <- gg + theme(axis.text.x=element_text(size=10))
gg <- gg + theme(axis.text.y=element_text(size=12))
ggplotly(gg, tooltip = "text")
```

Ottawa-Gatineau {data-navmenu="Cities"}
=======================================================================
row
-----------------------------------------------------------------------

###Buildings {.value-box}
```{r, echo=FALSE}
buildOttGat <- data2 %>%
  filter(cities == "Ott/Gat") %>%
  top_n(1, month) %>%
  select(buildings)

valueBox(comma(buildOttGat), icon = "ion-ios-home-outline", color = "#9ecae1")
```

###Users {.value-box}
```{r}
usersOttGat <- data2 %>%
  filter(cities == "Ott/Gat") %>%
  top_n(1, month) %>%
  select(usersBuild)

valueBox(usersOttGat, icon = "ion-ios-people-outline", color = "#9ecae1")
```

###Average number of tags {.value-box}
```{r}
tagsOttGat <- data2 %>%
  filter(cities == "Ott/Gat") %>%
  top_n(1, month) %>%
  select(averTagsBuild)

tagsOttGat$averTagsBuild <- round(tagsOttGat$averTagsBuild, 2)

valueBox(tagsOttGat, icon = "ion-ios-pricetags-outline", color = "#9ecae1")
```


row {data-height=400}
-----------------------------------------------------------------------

###Buildings mapped

```{r, echo=FALSE, message=FALSE}
 OttBuildGat <- data2 %>%
   filter(cities=="Ott/Gat") %>%
   select(cities, month, buildings)

#With a geom_line plot, you need to add group = 1 if only one group of observations
#to avoid the warning message each is obs is one group
gg <- ggplot(OttBuildGat, aes(month, buildings, group = 1, text = comma(buildings)))
gg <- gg + geom_line(position = "identity", color="#6baed6")
gg <- gg + scale_y_continuous(labels = comma)
gg <- gg + scale_x_date(breaks = as.Date(seq(as.Date("2016-07-15"), 
                            as.Date(date), by = "1 month")), date_labels ="%b %y")
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major.x= element_blank())
gg <- gg + theme(panel.grid.major.y=element_line(linetype = "dashed"))
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks=element_line(colour="#ececec"))
gg <- gg + theme(axis.text.x=element_text(size=12))
gg <- gg + theme(axis.text.y=element_text(size=10))
ggplotly(gg, tooltip = "text")
```

row {data-height=600}
-------------------------------------------------------------------
###Buildings by type
```{r}
buildTypeOttGat <- BuildOttGat@data %>% 
  group_by(building) %>%
  summarise(numB = length(building)) %>%
  arrange(desc(numB)) %>%
  filter(numB > 50)

gg <- ggplot(buildTypeOttGat, aes(x=numB, y=reorder(building, numB), text = comma(numB)))
gg <- gg + geom_segment(aes(xend = 0, yend=building), color="#ececec")
gg <- gg + geom_point(color = "#3282bd", size = 2)
gg <- gg + scale_x_continuous(expand = c(0.1,0), labels = comma)
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major = element_blank())
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks.y=element_blank())
gg <- gg + theme(axis.text.x=element_text(size=9))
gg <- gg + theme(axis.text.y=element_text(size=12))
ggplotly(gg, tooltip = "text")
```

### Missing address fields in percentage
```{r}

MissAddOttGat <- BuildOttGat@data %>%
  select(addr.street, addr.housenumber, addr.city, addr.postcode)

MeanAddrOttGat <- MissAddOttGat %>%
  summarise_all(funs(mean(is.na(.))*100)) %>%
  gather(Field, meanNA) %>%
  mutate(Field = fct_recode(Field, "Street" = "addr.street", 
                            "Street Number" = "addr.housenumber",
                            "City" = "addr.city",
                            "Postal Code" = "addr.postcode"))

gg <- ggplot(MeanAddrOttGat, aes(x=reorder(Field, meanNA), y=meanNA, text = round(meanNA, 2)))
gg <- gg + geom_segment(aes(xend = Field, yend=0), color="#ececec")
gg <- gg + geom_point(color = "#3282bd", size = 2)
gg <- gg + coord_flip()
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major = element_blank())
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks.y=element_blank())
gg <- gg + theme(axis.text.x=element_text(size=10))
gg <- gg + theme(axis.text.y=element_text(size=12))
ggplotly(gg, tooltip = "text")
```

###Number of tags

```{r}
OttGatTagsBuild <- data3 %>%
  filter(cities=="Ott/Gat") %>%
  select(cities, month, tagsBuild) %>%
  mutate(month = fct_recode(month, "2016-08-30" = "2016-08-01")) %>%
  mutate(month = ymd(month))

#28 because of February
gg <- ggplot(OttGatTagsBuild, aes(x=tagsBuild, y=month, text = comma(tagsBuild)))
gg <- gg + geom_segment(aes(xend = 0, yend=month), color="#ececec")
gg <- gg + geom_point(color = "#3282bd", size = 2)
gg <- gg + scale_x_continuous(expand = c(0.2,0), labels = comma)
gg <- gg + scale_y_date(breaks = as.Date(seq(as.Date("2016-08-25"), 
                            as.Date(date), by = "1 month")), date_labels ="%b %y")
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major = element_blank())
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks.y=element_blank())
gg <- gg + theme(axis.text.x=element_text(size=10))
gg <- gg + theme(axis.text.y=element_text(size=12))
ggplotly(gg, tooltip = "text")
```


Data
========================================================
```{r}
datatable(data, extensions = "Buttons", 
          options = list(dom="lfrtBip", buttons="csv"))
```


August 2016 {data-navmenu="Maps"}
========================================================
```{r, out.width = "1024px"}
knitr::include_graphics("Aug2016.jpg")
```

`r format(date, format='%B %Y')` {data-navmenu="Maps"}
========================================================
```{r, out.width = "1024px"}
knitr::include_graphics(MapDate)
```